<?php

class User_Controller_Browse_Password_Recover extends Nuo_Controller
{

	function execute($request)
	{
		$form = Nuo::getObject('user/browse/password/recover', 'form');

		if ($request -> isGet())
		{

		}

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$data = $form -> getData();

			$email = $data['email'];
			/**
			 * start process forget password
			 * 1. check if email exists
			 * 2. send an verify message to associate email
			 * 3. open verify code message to process blocking.
			 */

			$table = Nuo::getTable('user');

			$select = $table -> select() -> where('email=?', $email);

			$account = $table -> fetchRow($select);

			if (!$account)
			{
				$form -> addError('There is no account associate with this identity!');
			}
			else
			{
				Nuo::getApi('mail') -> send('user.password_verifyrequest', $email, array());
			}

		}

		return  $this -> render(array('form' => $form));

	}

}
